from django.db import models

# 行政区划
class Region(models.Model):
    code = models.BigIntegerField(primary_key=True, verbose_name="区划编号")
    name = models.CharField(max_length=32, verbose_name="区划名称")
    regionLevel = models.SmallIntegerField(db_column="region_level", verbose_name="区划等级，0国家，1省份/直辖市，2地市，3区县，4乡镇，5村委")
    sort = models.PositiveIntegerField(verbose_name="排序")
    remark = models.CharField(max_length=255,null=True,blank=True, verbose_name="备注")
    parentCode = models.ForeignKey(to='self', db_column="parent_code", db_constraint=False, on_delete=models.CASCADE, null=True, blank=True, verbose_name="父级id")

    def __str__(self):
        return self.name
    
    class Meta:
        db_table = 'system_region'
        ordering = ['sort']
        indexes = [
            models.Index(fields=['parentCode']),
            models.Index(fields=['code']),
            models.Index(fields=['name']),
            models.Index(fields=['regionLevel']),
        ]
